<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">申请列表</div>
		<div class="bg-white">
			<div class="home-form" v-if="showbutton&&showbtn">
				<a-button type="primary" :disabled="multipleSelection.length == 0" @click="addList">
					批量审核({{ multipleSelection.length }})</a-button>
			</div>
			<a-tabs :defaultActiveKey="isAgree" @change="callback">
				<a-tab-pane :key="item.ID" :tab="item.Name" v-for="(item, i) in TypeList"></a-tab-pane>
			</a-tabs>
			<div class="table">
				<el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%"
					tooltip-effect="dark" @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="55"></el-table-column>
					<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
					<el-table-column prop="Name" label="姓名/学号" min-width="100" fixed="left" align="center">
						<template slot-scope="scope">
							{{ scope.row.Name | testname }} / {{ scope.row.UserNo | testno }}
						</template>
					</el-table-column>
					<el-table-column prop="Reason" label="申请原因" min-width="100"></el-table-column>
					<el-table-column prop="AddTime" label="申请时间" min-width="120" align="center"></el-table-column>
					<el-table-column prop="Reason" label="状态" min-width="100">
						<template slot-scope="scope">
							<span v-if="scope.row.IsAgree==null">
								<a-tag color="orange">待审核</a-tag>
							</span>
							<span v-if="scope.row.IsAgree==true">
						 	<a-tag color="green">通过</a-tag>
							</span>
							<span v-if="scope.row.IsAgree==false">
						  <a-tag color="pink">未通过</a-tag>
							</span>
						</template>
					</el-table-column>
					<el-table-column prop="ReplyComment" label="审核内容" min-width="120" show-overflow-tooltip
						v-if="isAgree=='true' || isAgree=='false'">
						<template slot-scope="scope">
							{{scope.row.ReplyComment}}
						</template>
					</el-table-column>
					<el-table-column prop="IsEnable" label="操作" width="130">
						<template slot-scope="scope">
							<div class="user-btn user-btn-auto">
								<span class="examine" v-if="scope.row.IsAgree==null"
									@click="modifyList(scope.row, 'modify')">审核</span>
								<span class="detail" @click="detail(scope.row)">详情</span>
							</div>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
					:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
					:total="pagination.total"></el-pagination>
			</div>
		</div>
		<applyJoin :approvalType="1" :text="text" v-show="showModal" @closeFun="closeFun(1)"></applyJoin>
		<batchApply :approvalType="1" :text="batchtext" v-show="batchshowModal" @closeFun="closeFun"></batchApply>
		<a-modal title="审核结果" :visible="visible" :confirm-loading="confirmLoading" @cancel="handleCancel"
			:footer="null">
			<div style="font-size: 16px;">
				<div>
					审核成功：
					<span style="color:green">{{ sunum }}</span>
					条
				</div>
				<div>
					审核失败：
					<span style="color:red">{{ errnum }}</span>
					条
				</div>
			</div>
		</a-modal>
		<detail :time="time" :isApplyList="true" :text="text" v-show="showModal1" @closeFun="closeFun(1)"></detail>
	</div>
</template>

<script>
	import Func from '@/utils/func';
	import detail from './userApplyClubRecordDeatil.vue'
	import {
		GetUserClubApplyPageList,
		DeleteClub,
		EnableClub,
		GetClubTypeList,
		GetClubProjectList,
		GetDepartList,
		UserGetClubDetail
	} from '@/api/follow';
	import applyJoin from '@/components/Apply';
	import batchApply from '@/components/BatchApply';
	import Cache from '@/utils/cache';
	const data = [];
	export default {
		components: {
			applyJoin,
			batchApply,
			detail
		},
		data() {
			return {
				data,
				showModal1:false,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				TypeList: [{
						ID: 'null',
						Name: '待审核'
					},
					{
						ID: 'true',
						Name: '审核通过'
					},
					{
						ID: 'false',
						Name: '审核未通过'
					}
				],
				multipleSelection: [],
				addIf: false,
				text: {},
				batchtext: [],
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				batchshowModal: false,
				sunum: 0,
				errnum: 0,
				showbtn: true,
				managerPower: '',
				ChairmanNo: '',
				thisChairmanNo: Cache.get('myInfo').UserNo,
				showbutton: false,
				isAgree: null
			};
		},
		computed: {},
		created() {
			this.getList();
			this.getOtherList();
		},
		mounted() {},
		methods: {
			callback(key) {
				this.pagination.currentPage = 1;
				this.isAgree = key;
				this.getList();
			},
			detail(text) {
				this.text = {
					...text,
					time: new Date()
				}
				this.showModal1 = true
			},
			handleCancel(e) {
				this.visible = false;
				this.confirmLoading = false;
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			joinok() {
				this.text = this.selectList;
				this.showModal = true;
			},
			handleChange(val) {
				// this.currentRow = val;
				if (val == 'null') {
					this.showbtn = true;
				} else {
					this.showbtn = false;
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				data.isAgree = this.isAgree
				data.clubID = this.$route.query.ID;
				let res = await GetUserClubApplyPageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				// let res = await GetClubTypeList();
				// let res2 = await GetDepartList();
				let data = {};
				data.id = this.$route.query.ID;
				let res3 = await UserGetClubDetail(data);
				// this.TypeIDList = res.data.data;
				// this.DepartCodeList = res2.data.data;
				this.managerPower = res3.data.managerPower;
				this.ChairmanNo = res3.data.data.ChairmanNo;

				if (this.managerPower != null) {
					if (this.managerPower.IsAgreeManageMember == true) {
						this.showbutton = true;
					} else {
						this.showbutton = false;
					}
				} else if (this.ChairmanNo == this.thisChairmanNo) {
					this.showbutton = true;
				} else {
					this.showbutton = false;
				}
			},
			addList() {
				this.batchtext = this.multipleSelection;
				this.batchshowModal = !this.batchshowModal;
			},
			modifyList(text) {
				// text = Object.assign(text, {
				// 	time: new Date()
				// });
				this.showModal = !this.showModal;
				this.text = text;
			},
			enableList(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定要${text.IsEnable ? '停用' : '启用'}该学生组织吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await EnableClub(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			deleteList(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该学生组织吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await DeleteClub(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			seeList(text, name) {
				let path = '';
				if (name == 'teacher') {
					path = 'ClubTeacher';
				} else if (name == 'manage') {
					path = 'ClubManagerList';
				} else {
					path = 'ClubMember';
				}
				this.$router.push({
					name: path,
					query: {
						ID: text.ID
					}
				});
			},
			closeFun(index, scount, ecount) {
				if (index == 2) {
					this.sunum = scount;
					this.errnum = ecount;
					this.visible = true;
				}
				this.showModal = false;
				this.showModal1 = false;
				this.batchshowModal = false;
				this.getList();
			}
		}
	};
</script>
